package com.beiye.drivertransport.SubActivity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.beiye.drivertransport.R;
import com.beiye.drivertransport.activity.TwoBaseAty;
import com.beiye.drivertransport.bean.AuditBean;
import com.beiye.drivertransport.bean.SpecifiedPhotoBean;
import com.beiye.drivertransport.config.AppInterfaceConfig;
import com.beiye.drivertransport.http.Login;
import com.beiye.drivertransport.utils.Utils;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.githang.statusbar.StatusBarCompat;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;


import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

//企业管理员安全学习审核
public class EnterpriseAuditActivity extends TwoBaseAty {


    ImageView img_audit_back;

    EditText ed_audit;

    TextView tv_date;//日期

    TextView tv_audit3;//筛选

    TextView tv_audit1;//搜索

    RelativeLayout re_audit;//跳转到未完成

    ListView lv_audit;

    View empty_view;
    //    @Bind(R.id.tv1)
//    TextView mBtnPrePage;//首页
//    @Bind(R.id.tv4)
//    TextView mBtnNextPage;//尾页
//    @Bind(R.id.tv2)
//    TextView mBtnPreItem;//上一页
//    @Bind(R.id.tv3)
//    TextView mBtnNextItem;//下一页
//    @Bind(R.id.tv5)
//    TextView mTvPageNo;//显示几页
//    @Bind(R.id.re_num)
//    RelativeLayout re_num;
    //被选着的索引
    //  private int selectIndex = 0;
    private int firstIndex = 1;
    private int pageSize = 10000;
    private PopupWindow mPopWindow;
    ArrayList<AuditBean.RowsBean> auditlist = new ArrayList<>();
    // private PageHelper<AuditBean.RowsBean> mPageDaoImpl;
    private SubAuditApt subAuditApt;

    @Override
    public int getLayoutId() {
        return R.layout.activity_enterprise_audit;

    }


    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.img_audit_back) {
            finish();
            //            case R.id.tv1://首页
//                headPage();
//                break;
//            case R.id.tv4://尾页
//                lastPage();
//                break;
//            case R.id.tv2://上一页
//                prePage();
//                break;
//            case R.id.tv3://下一页
//                nextPage();
//                break;
        } else if (id == R.id.re_audit) {
            if (Utils.isFastDoubleClick()) {
                return;
            }
            SharedPreferences sp = getSharedPreferences("EnterpriseAuditActivity",
                    Context.MODE_PRIVATE);

            String orgId = sp.getString("orgId", "");
            int minPer = sp.getInt("minPer", 0);
            Bundle bundle = new Bundle();

            bundle.putString("orgId", orgId);
            bundle.putInt("minPer", minPer);
            startActivity(UnfinishedLearningActivity.class, bundle);
        } else if (id == R.id.tv_audit2) {
            showDateYearpopwindow();
        } else if (id == R.id.tv_audit3) {
            SharedPreferences sp3 = getSharedPreferences("finishMark",
                    Context.MODE_PRIVATE);
            SharedPreferences.Editor edit2 = sp3.edit();
            edit2.clear();
            edit2.commit();
            SharedPreferences sp4 = getSharedPreferences("CheckMark",
                    Context.MODE_PRIVATE);
            SharedPreferences.Editor edit1 = sp4.edit();
            edit1.clear();
            edit1.commit();
            showScreenpopwindow();//筛选
        } else if (id == R.id.tv_audit1) {//搜索

            SharedPreferences sp2 = getSharedPreferences("EnterpriseAuditActivity",
                    Context.MODE_PRIVATE);
            //     String adId1 = sp2.getString("adId", "");
            String orgId1 = sp2.getString("orgId", "");
            String setYm = sp2.getString("setYm", "");
            String name = ed_audit.getText().toString().trim();
//                SharedPreferences sp5 = getSharedPreferences("finishMark",
//                        Context.MODE_PRIVATE);
//                SharedPreferences sp6 = getSharedPreferences("CheckMark",
//                        Context.MODE_PRIVATE);
//                int finishMark = sp5.getInt("finishMark", 12);
//                int mark = sp6.getInt("mark", -1);
            showLoadingDialog("");
            if (name.equals("")) {
                new Login().getfindUnChUserAudit(orgId1, setYm, "", 12, 12, -1, 0, firstIndex, pageSize, this, 1);
            } else {
                new Login().getfindUnChUserAudit(orgId1, setYm, name, 12, 12, -1, 0, firstIndex, pageSize, this, 1);
            }

//                if(name.equals(""))
//                {
//                   if(finishMark==12)
//                   {
//                       if(mark==-1)
//                       {
//                           new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,"",12,12,-1,0,firstIndex,pageSize,this,1);
//                       }else if(mark==1)
//                       {
//                           new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,"",12,12,1,0,firstIndex,pageSize,this,1);
//                       }else if(mark==2)
//                       {
//                           new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,"",12,12,2,0,firstIndex,pageSize,this,1);
//                       }else if(mark==0)
//                       {
//                           new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,"",12,12,0,0,firstIndex,pageSize,this,1);
//                       }
//                   }else if(finishMark==1)
//                   {
//                       if(mark==-1)
//                       {
//                           new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,"",12,1,-1,0,firstIndex,pageSize,this,1);
//                       }else if(mark==1)
//                       {
//                           new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,"",12,1,1,0,firstIndex,pageSize,this,1);
//                       }else if(mark==2)
//                       {
//                           new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,"",12,1,2,0,firstIndex,pageSize,this,1);
//                       }else if(mark==0)
//                       {
//                           new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,"",12,1,0,0,firstIndex,pageSize,this,1);
//                       }
//                   }else if(finishMark==2)
//                   {
//                       if(mark==-1)
//                       {
//                           new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,"",12,2,-1,0,firstIndex,pageSize,this,1);
//                       }else if(mark==1)
//                       {
//                           new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,"",12,2,1,0,firstIndex,pageSize,this,1);
//                       }else if(mark==2)
//                       {
//                           new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,"",12,2,2,0,firstIndex,pageSize,this,1);
//                       }else if(mark==0)
//                       {
//                           new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,"",12,2,0,0,firstIndex,pageSize,this,1);
//                       }
//                   }
//
//                }else{
//                    if(finishMark==12)
//                    {
//                        if(mark==-1)
//                        {
//                            new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,name,12,12,-1,0,firstIndex,pageSize,this,1);
//                        }else if(mark==1)
//                        {
//                            new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,name,12,12,1,0,firstIndex,pageSize,this,1);
//                        }else if(mark==2)
//                        {
//                            new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,name,12,12,2,0,firstIndex,pageSize,this,1);
//                        }else if(mark==0)
//                        {
//                            new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,name,12,12,0,0,firstIndex,pageSize,this,1);
//                        }
//                    }else if(finishMark==1)
//                    {
//                        if(mark==-1)
//                        {
//                            new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,name,12,1,-1,0,firstIndex,pageSize,this,1);
//                        }else if(mark==1)
//                        {
//                            new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,name,12,1,1,0,firstIndex,pageSize,this,1);
//                        }else if(mark==2)
//                        {
//                            new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,name,12,1,2,0,firstIndex,pageSize,this,1);
//                        }else if(mark==0)
//                        {
//                            new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,name,12,1,0,0,firstIndex,pageSize,this,1);
//                        }
//                    }else if(finishMark==2)
//                    {
//                        if(mark==-1)
//                        {
//                            new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,name,12,2,-1,0,firstIndex,pageSize,this,1);
//                        }else if(mark==1)
//                        {
//                            new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,name,12,2,1,0,firstIndex,pageSize,this,1);
//                        }else if(mark==2)
//                        {
//                            new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,name,12,2,2,0,firstIndex,pageSize,this,1);
//                        }else if(mark==0)
//                        {
//                            new Login().getfindUnChUserAudit(adId1,orgId1,beginTime,endTime,name,12,2,0,0,firstIndex,pageSize,this,1);
//                        }
//                    }
//                }
        }

    }

    @Override
    public void onBackPressed() {
//        SharedPreferences sp1 = getSharedPreferences("EnterpriseAuditActivity",
//                Context.MODE_PRIVATE);
//        SharedPreferences.Editor edit = sp1.edit();
//        edit.clear();
//        edit.commit();
        SharedPreferences sp3 = getSharedPreferences("finishMark",
                Context.MODE_PRIVATE);
        SharedPreferences.Editor edit2 = sp3.edit();
        edit2.clear();
        edit2.commit();
        SharedPreferences sp2 = getSharedPreferences("CheckMark",
                Context.MODE_PRIVATE);
        SharedPreferences.Editor edit1 = sp2.edit();
        edit1.clear();
        edit1.commit();
        super.onBackPressed();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        SharedPreferences sp1 = getSharedPreferences("EnterpriseAuditActivity",
                Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sp1.edit();
        edit.clear();
        edit.commit();
    }

    private void showScreenpopwindow() {

        //设置contentView
        View contentView = LayoutInflater.from(EnterpriseAuditActivity.this).inflate(R.layout.popwindowscreen_layout, null);
        mPopWindow = new PopupWindow(contentView,
                WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT, true);
        mPopWindow.showAtLocation(tv_audit3, Gravity.CENTER, 0, 0);
        FrameLayout fe_screen = (FrameLayout) contentView.findViewById(R.id.fe_screen);
        RelativeLayout re_screen = (RelativeLayout) contentView.findViewById(R.id.re_screen);
        final ImageView img_sign = (ImageView) contentView.findViewById(R.id.img_sign);
        final ImageView img_unsign = (ImageView) contentView.findViewById(R.id.img_unsign);
        final ImageView img_examine = (ImageView) contentView.findViewById(R.id.img_examine);
        final ImageView img_examine1 = (ImageView) contentView.findViewById(R.id.img_examine1);
        final ImageView img_examine2 = (ImageView) contentView.findViewById(R.id.img_examine2);
        TextView tv_sure = (TextView) contentView.findViewById(R.id.tv_sure);
        re_screen.setOnClickListener(null);
        fe_screen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mPopWindow.dismiss();
                SharedPreferences sp1 = getSharedPreferences("finishMark",
                        Context.MODE_PRIVATE);
                SharedPreferences.Editor edit = sp1.edit();
                edit.clear();
                edit.commit();
                SharedPreferences sp2 = getSharedPreferences("CheckMark",
                        Context.MODE_PRIVATE);
                SharedPreferences.Editor edit1 = sp2.edit();
                edit1.clear();
                edit1.commit();

            }
        });
        img_sign.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                img_sign.setImageResource(R.mipmap.signedpress);
                img_unsign.setImageResource(R.mipmap.unsignenormal);
                SharedPreferences sp = getSharedPreferences("finishMark",
                        Context.MODE_PRIVATE);
                SharedPreferences.Editor edit = sp.edit();
                edit.putInt("finishMark", 2);
                edit.commit();
            }
        });
        img_unsign.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                img_sign.setImageResource(R.mipmap.signednormal);
                img_unsign.setImageResource(R.mipmap.unsignedpress);
                SharedPreferences sp = getSharedPreferences("finishMark",
                        Context.MODE_PRIVATE);
                SharedPreferences.Editor edit = sp.edit();
                edit.putInt("finishMark", 1);
                edit.commit();
            }
        });
        img_examine.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                img_examine.setImageResource(R.mipmap.auditedpress);
                img_examine1.setImageResource(R.mipmap.passthroughnormal);
                img_examine2.setImageResource(R.mipmap.failedpassnormal);
                SharedPreferences sp = getSharedPreferences("CheckMark",
                        Context.MODE_PRIVATE);
                SharedPreferences.Editor edit = sp.edit();
                edit.putInt("mark", 0);
                edit.commit();
            }
        });
        img_examine1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                img_examine1.setImageResource(R.mipmap.passthroughpress);
                img_examine.setImageResource(R.mipmap.auditednormal);
                img_examine2.setImageResource(R.mipmap.failedpassnormal);
                SharedPreferences sp = getSharedPreferences("CheckMark",
                        Context.MODE_PRIVATE);
                SharedPreferences.Editor edit = sp.edit();
                edit.putInt("mark", 1);
                edit.commit();
            }
        });
        img_examine2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                img_examine2.setImageResource(R.mipmap.failedpasspress);
                img_examine1.setImageResource(R.mipmap.passthroughnormal);
                img_examine.setImageResource(R.mipmap.auditednormal);
                SharedPreferences sp = getSharedPreferences("CheckMark",
                        Context.MODE_PRIVATE);
                SharedPreferences.Editor edit = sp.edit();
                edit.putInt("mark", 2);
                edit.commit();
            }
        });
        tv_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mPopWindow.dismiss();
                SharedPreferences sp = getSharedPreferences("EnterpriseAuditActivity",
                        Context.MODE_PRIVATE);
//                String adId = sp.getString("adId", "");
                String orgId = sp.getString("orgId", "");
                String setYm = sp.getString("setYm", "");
                String name = ed_audit.getText().toString().trim();
                SharedPreferences sp1 = getSharedPreferences("finishMark",
                        Context.MODE_PRIVATE);
                SharedPreferences sp2 = getSharedPreferences("CheckMark",
                        Context.MODE_PRIVATE);
                int finishMark = sp1.getInt("finishMark", 12);
                int mark = sp2.getInt("mark", -1);
                showLoadingDialog("");
                initAuditData(orgId, setYm, name, finishMark, mark);

            }
        });
    }

    private void initAuditData(String orgId, String setYm, String name, int finishMark, int mark) {
        if (finishMark == 12) {

            if (mark == -1) {
                if (name.equals("")) {

                    new Login().getfindUnChUserAudit(orgId, setYm, "", 12, 12, -1, 0, firstIndex, pageSize, this, 1);
                } else {
                    new Login().getfindUnChUserAudit(orgId, setYm, name, 12, 12, -1, 0, firstIndex, pageSize, this, 1);
                }
            } else if (mark == 1) {
                if (name.equals("")) {

                    new Login().getfindUnChUserAudit(orgId, setYm, "", 12, 12, 1, 0, firstIndex, pageSize, this, 1);
                } else {
                    new Login().getfindUnChUserAudit(orgId, setYm, name, 12, 12, 1, 0, firstIndex, pageSize, this, 1);
                }
            } else if (mark == 2) {
                if (name.equals("")) {

                    new Login().getfindUnChUserAudit(orgId, setYm, "", 12, 12, 2, 0, firstIndex, pageSize, this, 1);
                } else {
                    new Login().getfindUnChUserAudit(orgId, setYm, name, 12, 12, 2, 0, firstIndex, pageSize, this, 1);
                }
            } else if (mark == 0) {
                if (name.equals("")) {

                    new Login().getfindUnChUserAudit(orgId, setYm, "", 12, 12, 0, 0, firstIndex, pageSize, this, 1);
                } else {
                    new Login().getfindUnChUserAudit(orgId, setYm, name, 12, 12, 0, 0, firstIndex, pageSize, this, 1);
                }
            }
        } else if (finishMark == 1) {
            if (mark == -1) {
                if (name.equals("")) {

                    new Login().getfindUnChUserAudit(orgId, setYm, "", 12, 1, -1, 0, firstIndex, pageSize, this, 1);
                } else {
                    new Login().getfindUnChUserAudit(orgId, setYm, name, 12, 1, -1, 0, firstIndex, pageSize, this, 1);
                }
            } else if (mark == 1) {
                if (name.equals("")) {

                    new Login().getfindUnChUserAudit(orgId, setYm, "", 12, 1, 1, 0, firstIndex, pageSize, this, 1);
                } else {
                    new Login().getfindUnChUserAudit(orgId, setYm, name, 12, 1, 1, 0, firstIndex, pageSize, this, 1);
                }
            } else if (mark == 2) {
                if (name.equals("")) {

                    new Login().getfindUnChUserAudit(orgId, setYm, "", 12, 1, 2, 0, firstIndex, pageSize, this, 1);
                } else {
                    new Login().getfindUnChUserAudit(orgId, setYm, name, 12, 1, 2, 0, firstIndex, pageSize, this, 1);
                }
            } else if (mark == 0) {
                if (name.equals("")) {

                    new Login().getfindUnChUserAudit(orgId, setYm, "", 12, 1, 0, 0, firstIndex, pageSize, this, 1);
                } else {
                    new Login().getfindUnChUserAudit(orgId, setYm, name, 12, 1, 0, 0, firstIndex, pageSize, this, 1);
                }
            }
        } else if (finishMark == 2) {
            if (mark == -1) {
                if (name.equals("")) {

                    new Login().getfindUnChUserAudit(orgId, setYm, "", 12, 2, -1, 0, firstIndex, pageSize, this, 1);
                } else {
                    new Login().getfindUnChUserAudit(orgId, setYm, name, 12, 2, -1, 0, firstIndex, pageSize, this, 1);
                }
            } else if (mark == 1) {
                if (name.equals("")) {

                    new Login().getfindUnChUserAudit(orgId, setYm, "", 12, 2, 1, 0, firstIndex, pageSize, this, 1);
                } else {
                    new Login().getfindUnChUserAudit(orgId, setYm, name, 12, 2, 1, 0, firstIndex, pageSize, this, 1);
                }
            } else if (mark == 2) {
                if (name.equals("")) {

                    new Login().getfindUnChUserAudit(orgId, setYm, "", 12, 2, 2, 0, firstIndex, pageSize, this, 1);
                } else {
                    new Login().getfindUnChUserAudit(orgId, setYm, name, 12, 2, 2, 0, firstIndex, pageSize, this, 1);
                }
            } else if (mark == 0) {
                if (name.equals("")) {

                    new Login().getfindUnChUserAudit(orgId, setYm, "", 12, 2, 0, 0, firstIndex, pageSize, this, 1);
                } else {
                    new Login().getfindUnChUserAudit(orgId, setYm, name, 12, 2, 0, 0, firstIndex, pageSize, this, 1);
                }
            }
        }


    }

    private void showDateYearpopwindow() {
        TimePickerView pvTime = new TimePickerBuilder(EnterpriseAuditActivity.this, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date2, View v) {//选中事件回调
                String time = getTime(date2);
//                String year = time.substring(0, 5);
//                String month = time.substring(5);
                tv_date.setText(time);
//                Calendar cal = Calendar.getInstance();
//                cal.set(Calendar.YEAR, Integer.parseInt(year.substring(0, 4)));
//                cal.set(Calendar.MONTH, Integer.parseInt(month.substring(0, 2)));
//                cal.set(Calendar.DAY_OF_MONTH, 1);
//                cal.add(Calendar.DAY_OF_MONTH, -1);
//                Date lastDate = cal.getTime();
//                cal.set(Calendar.DAY_OF_MONTH, 1);
//                Date firstDate = cal.getTime();
//                String beginTime = new SimpleDateFormat("yyyy-MM-dd 00:00:00").format(firstDate);
//                String endTime = new SimpleDateFormat("yyyy-MM-dd 23:59:59").format(lastDate);
                SharedPreferences sp = getSharedPreferences("EnterpriseAuditActivity",
                        Context.MODE_PRIVATE);
                SharedPreferences.Editor edit = sp.edit();
                edit.putString("setYm", time);
                edit.commit();
                requestData();

            }
        })
                .setType(new boolean[]{true, true, false, false, false, false})//默认全部显示
                .setCancelText("取消")//取消按钮文字
                .setSubmitText("确定")//确认按钮文字
                .setTitleSize(20)//标题文字大小
//                        .setTitleText("请选择时间")//标题文字
                .setOutSideCancelable(true)//点击屏幕，点在控件外部范围时，是否取消显示
                .isCyclic(true)//是否循环滚动
                .setTextColorCenter(Color.BLACK)//设置选中项的颜色
                .setTitleColor(Color.BLACK)//标题文字颜色
                .setSubmitColor(Color.BLACK)//确定按钮文字颜色
                .setCancelColor(Color.BLACK)//取消按钮文字颜色
//                        .setTitleBgColor(0xFF666666)//标题背景颜色 Night mode
//                        .setBgColor(0xFF333333)//滚轮背景颜色 Night mode
//                        .setRange(calendar.get(Calendar.YEAR) - 20, calendar.get(Calendar.YEAR) + 20)//默认是1900-2100年
//                        .setDate(selectedDate)// 如果不设置的话，默认是系统时间*/
//                        .setRangDate(startDate,endDate)//起始终止年月日设定
//                        .setLabel("年","月","日","时","分","秒")
                .isCenterLabel(false) //是否只显示中间选中项的label文字，false则每项item全部都带有label。
//                        .isDialog(true)//是否显示为对话框样式
                .build();
        pvTime.setDate(Calendar.getInstance());//注：根据需求来决定是否使用该方法（一般是精确到秒的情况），此项可以在弹出选择器的时候重新设置当前时间，避免在初始化之后由于时间已经设定，导致选中时间与当前时间不匹配的问题。
        pvTime.show();


    }

    public String getTime(Date date) {//可根据需要自行截取数据显示
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
        return format.format(date);
    }

    @Override
    public void initData() {
        img_audit_back = (ImageView) findViewById(R.id.img_audit_back);
        ed_audit = (EditText) findViewById(R.id.ed_audit);
        tv_date = (TextView) findViewById(R.id.tv_audit2);
        tv_audit3 = (TextView) findViewById(R.id.tv_audit3);
        tv_audit1 = (TextView) findViewById(R.id.tv_audit1);
        re_audit = (RelativeLayout) findViewById(R.id.re_audit);
        lv_audit = (ListView) findViewById(R.id.lv_audit);
        empty_view = (View) findViewById(R.id.empty_view);

        StatusBarCompat.setStatusBarColor(this, Color.parseColor("#1F80C4"));
        Bundle bundle = getIntent().getExtras();
        String adId = bundle.getString("adId");
        String orgId = bundle.getString("orgId");
        int minPer = bundle.getInt("minPer");


        ed_audit.setOnTouchListener(new View.OnTouchListener() {

            @SuppressLint("ClickableViewAccessibility")
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (MotionEvent.ACTION_DOWN == event.getAction()) {
                    ed_audit.setCursorVisible(true);// 再次点击显示光标
                }
                return false;
            }
        });

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");// HH:mm:ss
        //获取当前时间
        Date date = new Date(System.currentTimeMillis());
        String format = simpleDateFormat.format(date);
//        String year = format.substring(0, 5);
//        String month = format.substring(5);
        tv_date.setText(format);

//                Calendar cal = Calendar.getInstance();
//                cal.set(Calendar.YEAR, Integer.parseInt(year.substring(0, 4)));
//              cal.set(Calendar.MONTH, Integer.parseInt(month.substring(0, 2)));
//                cal.set(Calendar.DAY_OF_MONTH, 1);
//                cal.add(Calendar.DAY_OF_MONTH, -1);
//                Date lastDate = cal.getTime();
//                cal.set(Calendar.DAY_OF_MONTH, 1);
//                Date firstDate = cal.getTime();
//        String beginTime = new SimpleDateFormat("yyyy-MM-dd 00:00:00").format(firstDate);
//        String endTime = new SimpleDateFormat("yyyy-MM-dd 23:59:59").format(lastDate);
        SharedPreferences sp = getSharedPreferences("EnterpriseAuditActivity",
                Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = sp.edit();
        edit.putString("adId", adId);
        edit.putString("orgId", orgId);
        edit.putString("setYm", format);
        edit.putInt("minPer", minPer);
        edit.commit();


        lv_audit.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                if (Utils.isFastDoubleClick()) {
                    return;
                }
                final int sn = auditlist.get(position).getSn();//学时序列号
                final String chName = auditlist.get(position).getChName();//学时名称
                final long updateDate = auditlist.get(position).getUpdateDate();//学时完成日期
                final String userName = auditlist.get(position).getUserName();//学生姓名
                final long creationDate = auditlist.get(position).getCreationDate();
                final String photoUrl = auditlist.get(position).getPhotoUrl();//学员头像
                //     List<AuditBean.RowsBean.PhotoListBean> photoList = auditlist.get(position).getPhotoList();//学习时拍照
                final int chNo = auditlist.get(position).getChNo();//学时数
                final int checkMark = auditlist.get(position).getCheckMark();//审核状态
                final String checkUserName = auditlist.get(position).getCheckUserName();//审核人姓名
                final String checkDesc = auditlist.get(position).getCheckDesc();//审核描述
                final int spotCheckMark = auditlist.get(position).getSpotCheckMark();//抽查状态
                final String signPicUrl = auditlist.get(position).getSignPicUrl();//学员签名
                OkGo.get(AppInterfaceConfig.BASE_URL + "course/userTcPhoto/find/" + sn)
                        .tag(this)
                        .execute(new StringCallback() {
                            @Override
                            public void onSuccess(String s, Call call, Response response) {

                                SpecifiedPhotoBean photoBean = JSON.parseObject(s, SpecifiedPhotoBean.class);
                                List<SpecifiedPhotoBean.RowsBean> rows = photoBean.getRows();
                                Bundle bundle = new Bundle();
                                bundle.putString("chName", chName);
                                bundle.putString("userName", userName);
                                bundle.putInt("sn", sn);
                                bundle.putLong("updateDate", updateDate);
                                bundle.putLong("creationDate", creationDate);
                                bundle.putString("photoUrl", photoUrl);
                                bundle.putInt("chNo", chNo);
                                bundle.putInt("checkMark", checkMark);
                                bundle.putString("checkUserName", checkUserName);
                                bundle.putString("checkDesc", checkDesc);
                                bundle.putInt("spotCheckMark", spotCheckMark);
                                bundle.putString("signPicUrl", signPicUrl);
                                bundle.putSerializable("photoList", (Serializable) rows);
                                //startActivity(SubEnterpriseAuditActivity.class, bundle);
                            }

                            @Override
                            public void onError(Call call, Response response, Exception e) {
                                super.onError(call, response, e);

                            }
                        });


            }
        });
    }

    @Override
    protected void onResume() {
//        SharedPreferences sp = getSharedPreferences("EnterpriseAuditActivity",
//                Context.MODE_PRIVATE);
//        String adId = sp.getString("adId", "");
//        String orgId = sp.getString("orgId", "");
//        String beginTime = sp.getString("beginTime", "");
//        String endTime = sp.getString("endTime", "");
//        String name = ed_audit.getText().toString().trim();
//        SharedPreferences sp1 = getSharedPreferences("finishMark",
//                Context.MODE_PRIVATE);
//        SharedPreferences sp2 = getSharedPreferences("CheckMark",
//                Context.MODE_PRIVATE);
//        int finishMark = sp1.getInt("finishMark", 12);
//        int mark = sp2.getInt("mark", -1);
//        initAuditData(adId,orgId,beginTime,endTime,name,finishMark,mark);
        SharedPreferences sp = getSharedPreferences("EnterpriseAuditActivity",
                Context.MODE_PRIVATE);
        String orgId = sp.getString("orgId", "");
        String setYm = sp.getString("setYm", "");

        String name = ed_audit.getText().toString().trim();

        if (name.equals("")) {
            new Login().getfindUnChUserAudit(orgId, setYm, "", 12, 12, -1, 0, firstIndex, pageSize, this, 1);
        } else {
            new Login().getfindUnChUserAudit(orgId, setYm, name, 12, 12, -1, 0, firstIndex, pageSize, this, 1);
        }
        super.onResume();
    }

    @Override
    public void requestData() {

        SharedPreferences sp = getSharedPreferences("EnterpriseAuditActivity",
                Context.MODE_PRIVATE);
        String orgId = sp.getString("orgId", "");
        String setYm = sp.getString("setYm", "");
        String name = ed_audit.getText().toString().trim();
        showLoadingDialog("");
        if (name.equals("")) {
            new Login().getfindUnChUserAudit(orgId, setYm, "", 12, 12, -1, 0, firstIndex, pageSize, this, 1);
        } else {
            new Login().getfindUnChUserAudit(orgId, setYm, name, 12, 12, -1, 0, firstIndex, pageSize, this, 1);
        }

    }

    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        if (what == 1) {
            dismissLoadingDialog();
            AuditBean auditBean = JSON.parseObject(result, AuditBean.class);
            List<AuditBean.RowsBean> rows = auditBean.getRows();
            if (rows.size() == 0) {
                //   re_num.setVisibility(View.GONE);
                lv_audit.setEmptyView(empty_view);
                lv_audit.setAdapter(null);
                return;
            }
            auditlist.clear();
            auditlist.addAll(rows);
//            re_num.setVisibility(View.VISIBLE);
//            //每次读10条数据
//            if (auditlist.size() < 10) {
//                mPageDaoImpl = new PageHelper<AuditBean.RowsBean>(auditlist, auditlist.size());
//            } else if (auditlist.size() >= 10) {
//                mPageDaoImpl = new PageHelper<AuditBean.RowsBean>(auditlist, 10);
//            }

            subAuditApt = new SubAuditApt(EnterpriseAuditActivity.this, auditlist);
            lv_audit.setAdapter(subAuditApt);
            //设置当前页码与总页码
            //   mTvPageNo.setText("当前" + mPageDaoImpl.getCurrentPage() + " 页/共 " + mPageDaoImpl.getPageNum() + "页");


        }
        super.onSuccess(result, call, response, what);
    }

//    private void prePage() {
//        if (selectIndex == 0) {
//            if (mPageDaoImpl.getCurrentPage() >= 1) {
//                mPageDaoImpl.prePage();
//            }
//            subAuditApt.setData(mPageDaoImpl.currentList());
//            lv_audit.setSelection(subAuditApt.getCount() - 1);
//            mTvPageNo.setText("当前"+mPageDaoImpl.getCurrentPage() + " 页/共 " + mPageDaoImpl.getPageNum()+"页");
//        } else {
//            return;
//        }
//    }

//    private void nextPage() {
//        if (mPageDaoImpl.getCurrentPage() <= mPageDaoImpl.getPageNum()) {
//            mPageDaoImpl.nextPage();
//        }
//        subAuditApt.setData(mPageDaoImpl.currentList());
//        lv_audit.setSelection(0);
//        mTvPageNo.setText("当前"+mPageDaoImpl.getCurrentPage() + " 页/共 " + mPageDaoImpl.getPageNum()+"页");
//    }


//    private void lastPage() {
//        if (mPageDaoImpl.getCurrentPage() != mPageDaoImpl.getPageNum()) {
//            mPageDaoImpl.lastPage();
//        }
//        subAuditApt.setData(mPageDaoImpl.currentList());
//        mTvPageNo.setText("当前"+mPageDaoImpl.getCurrentPage() + " 页/共 " + mPageDaoImpl.getPageNum()+"页");
//    }

//    private void headPage() {
//        if (mPageDaoImpl.getCurrentPage() != 1) {
//            mPageDaoImpl.headPage();
//        }
//        subAuditApt.setData(mPageDaoImpl.currentList());
//        mTvPageNo.setText("当前"+mPageDaoImpl.getCurrentPage() + " 页/共 " + mPageDaoImpl.getPageNum()+"页");
//    }


    public class SubAuditApt extends BaseAdapter {

        private Context mContext;
        private List<AuditBean.RowsBean> mDatas;
        private String dateStr;
        private String dateStr1;

        public SubAuditApt(Context context, List<AuditBean.RowsBean> datas) {
            this.mContext = context;
            this.mDatas = datas;
        }

        @Override
        public int getCount() {
            return mDatas == null ? 0 : mDatas.size();
        }

        @Override
        public Object getItem(int position) {
            return mDatas == null ? null : mDatas.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder mHolder;
            if (convertView == null) {
                convertView = LayoutInflater.from(mContext).inflate(R.layout.audit_item_layout, parent, false);
                mHolder = new ViewHolder();
                mHolder.tv_date = (TextView) convertView.findViewById(R.id.tv_audit);//学时完成日期
                mHolder.tv_mark = (TextView) convertView.findViewById(R.id.tv_audit1);//审核标记
                mHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_audit4);//驾驶员名称
                mHolder.tv_chname = (TextView) convertView.findViewById(R.id.tv_audit5);//学时名称
                mHolder.img_mark = (ImageView) convertView.findViewById(R.id.img_audit);//审核按钮

                convertView.setTag(mHolder);
            }
            mHolder = (ViewHolder) convertView.getTag();
            long updateDate = mDatas.get(position).getUpdateDate();
            long creationDate = mDatas.get(position).getCreationDate();
            //mill为你龙类型的时间戳
            if (updateDate > 0) {
                Date date = new Date(updateDate);

                try {
                    //yyyy表示年MM表示月dd表示日
                    //yyyy-MM-dd是日期的格式，比如2015-12-12如果你要得到2015年12月12日就换成yyyy年MM月dd日
                    SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日");
                    //进行格式化
                    dateStr = sdf.format(date);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                mHolder.tv_date.setText(dateStr);
            } else {
                if (creationDate > 0) {
                    Date date = new Date(creationDate);

                    try {
                        //yyyy表示年MM表示月dd表示日
                        //yyyy-MM-dd是日期的格式，比如2015-12-12如果你要得到2015年12月12日就换成yyyy年MM月dd日
                        SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日");
                        //进行格式化
                        dateStr1 = sdf.format(date);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    mHolder.tv_date.setText(dateStr1);
                } else {

                    mHolder.tv_date.setText("");
                }
            }
            int checkMark = mDatas.get(position).getCheckMark();
            if (checkMark == 0) {
                mHolder.img_mark.setImageResource(R.mipmap.bj_03);
                mHolder.tv_mark.setText("审核");
            } else if (checkMark == 1) {
                mHolder.img_mark.setImageResource(R.mipmap.bj_09);
                mHolder.tv_mark.setText("查看");
            } else if (checkMark == 2) {
                mHolder.img_mark.setImageResource(R.mipmap.bj_21);
                mHolder.tv_mark.setText("查看");
            }
            String userName = mDatas.get(position).getUserName();
            if (userName == null) {
                mHolder.tv_name.setText("");
            } else {
                mHolder.tv_name.setText(userName);
            }

            String chName = mDatas.get(position).getChName();
            if (chName == null) {
                mHolder.tv_chname.setText("");
            } else {
                mHolder.tv_chname.setText(chName);
            }
            return convertView;
        }

        class ViewHolder {
            public TextView tv_date;
            public TextView tv_mark;
            public TextView tv_name;
            public TextView tv_chname;
            public ImageView img_mark;

        }

//        public void setData(List<AuditBean.RowsBean> datas) {
//            mDatas = datas;
//            notifyDataSetChanged();
//        }
    }
}
